<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>升腾客户管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="/X-admin/css/font.css">
    <link rel="stylesheet" href="/X-admin/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="/X-admin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/X-admin/js/xadmin.js"></script>
    <script type="text/javascript" src="/static/js/ajaxfileupload.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
     <style type="text/css">
       *
        {
            margin: 0;
            padding: 0;
        }
        /*蓝色按钮,绝对定位*/
        .blueButton
        {
            display: block;
            width: 102.5px;
            height: 38px;
            background-color: #3385ff;
            color: #fff;
            text-decoration: none;
            text-align: center;
            font:normal normal normal 16px/40px 'Microsoft YaHei';
            cursor: pointer;
            border-radius: 4px;
            float:left;
        }
        .blueButton:hover
        {
            text-decoration: none;
        }
        /*自定义上传,位置大小都和a完全一样,而且完全透明*/
        .myFileUpload
        {
        	position: absolute;
            display: block;
            width: 100px;
            height: 40px;
            opacity: 0;
        }
     </style>
  </head>
  
  <body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        {:$nav}
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace('{:url('Admin/Deposit/silverList')}');" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
<!--     <div class="x-body">
      <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so" action="{:url('Admin/Deposit/silverList')}">
          <input class="layui-input" placeholder="开始日" name="start_time" value="{notempty name="$filter.start_time"}{$filter.start_time}{/notempty}" id="start" id="start">
          <input class="layui-input" placeholder="截止日" name="end_time" value="{notempty name="$filter.end_time"}{$filter.end_time}{/notempty}"  id="end">
          <input type="text" name="keyword"  placeholder="请输入充值消费代码" autocomplete="off" value="{notempty name="$filter.keyword"}{$filter.keyword}{/notempty}"  class="layui-input">
          <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
      </div> -->

      <xblock>
      <div>
      	<a href='javascript:void(0);' class="blueButton">选择文件</a>
		<input type='file' name='myfile' class="myFileUpload" id="fileUpload"  onchange="uploadExcelFile();"/>
		<button type="button" class="layui-btn" id="batchAdd" >修改积分</button>
		<button class="layui-btn layui-btn-danger" onclick="del();">清空数据</button>
	  </div>

      </xblock>

      <div class="layui-form news_list">
      <table class="layui-table" lay-filter="demo" id="aas">
        <thead>
          <tr>
            <th>
              <input type="checkbox" name="" lay-skin="primary" lay-filter="filter" id="allChoose" />
            </th>
			<th>用户ID</th>
            <th>银卡号</th>    
			<th>增加积分</th>
			<th>充值时间</th>
        </thead>
        <tbody>{foreach name="deposit" item="vo"}		
          <tr>
            <td>
              <input type="checkbox" name="noiddel" lay-skin="primary" lay-filter="itemChoose" value="{$vo.id}"/>
            </td>
			<td>{$vo.user_id}</td>

            <td>{$vo.vip_no}</td>
			<td>{$vo.add_score}</td>
            <td>{$vo.create_time|date="Y-m-d H:i",###}</td>
          </tr>{/foreach}
        </tbody>
      </table>
      </div>
      <div class="page">
        <div>
		{$deposit->render()}
        </div>
      </div>

    </div>
    <script>
    //导入数据
    	function uploadExcelFile() {
	       $.ajaxFileUpload({
	           url:"{:url('Admin/Deposit/excel')}",
	           type:"POST",
	           fileElementId :"fileUpload",
	           success:function (data) {
	           	   console.log(data);
	           	   layer.msg('导入成功');
	           	   location.reload();
	           },
	           error:function(erro){
	               layer.msg('导入失败');
	           }
	       });
	   }
	//导入数据清空
    	function del() {
            layer.confirm('确定要清空所有数据吗？', {
                time: 20000, //20s后自动关闭
                btn: ['确定', '取消'],
                yes: function (index) {
				 	$.post("{:url('admin/deposit/abcDel')}",
				            function(data){
								if(data.code=='1'){
									layer.msg('增加成功');
									location.reload();
								}else{
									layer.msg('清空失败');
								}
					        }
				    );
                }
            });
	   }
	//多选框
	layui.use(['layer','jquery','table','form'], function() {
	$ = layui.jquery;
	var form = layui.form;
	var layer = layui.layer;
	form.on('checkbox(filter)', function(data){

	  console.log(data.elem); //得到checkbox原始DOM对象
	  console.log(data.elem.checked); //是否被选中，true或者false
	  console.log(data.value); //复选框value值，也可以通过data.elem.value得到
	  console.log(data.othis); //得到美化后的DOM对象
	  		var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
		    child.each(function(index, item){
		      item.checked = data.elem.checked;
		    });
		    form.render('checkbox');
	});

    form.on('checkbox(itemChoose)', function (data) {
		console.log(data.elem); //得到checkbox原始DOM对象
		console.log(data.elem.checked); //是否被选中，true或者false
		console.log(data.value); //复选框value值，也可以通过data.elem.value得到
		console.log(data.othis); //得到美化后的DOM对象
        var sib = $(data.elem).parents('table').find('tbody input[type="checkbox"]:checked').length;
        var total = $(data.elem).parents('table').find('tbody input[type="checkbox"]').length;
        if (sib == total) {
            $(data.elem).parents('table').find('thead input[type="checkbox"]').prop("checked", true);
            form.render();
        } else {
            $(data.elem).parents('table').find('thead input[type="checkbox"]').prop("checked", false);
            form.render();
        }
    }); 

	$('#batchAdd').click(function () {
                var noList = new Array();
                $("input:checkbox[name='noiddel']:checked").each(function () {
                    noList.push($(this).val());
                });
                if (noList.length == 0) {
                    layer.open({
                        title: '提示',
                        content: '请选择增加的数据'
                    });
                    return false;
                }
                console.log(noList);
                layer.confirm('确定要增加积分吗？', {
                    time: 20000, //20s后自动关闭
                    btn: ['确定', '取消'],
                    yes: function (index) {
                        layer.close(index);
 
					 	$.post("{:url('admin/deposit/pointAdd')}",
					            {'ids':noList},
					            function(data){
									if(data.code=='1'){
										layer.msg('增加成功');
										location.reload();
									}else{
										layer.msg('增加失败');
										//location.reload();
									}
						        }
					    );
                    }
                });
            });
});
    



      layui.use('laydate', function(){
        var laydate = layui.laydate;
        
        //执行一个laydate实例
        laydate.render({
          elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
          elem: '#end' //指定元素
        });
      });

       /*用户-停用*/
      function member_stop(obj,id){
          layer.confirm('确认改变状态吗？',function(index){ 
              if($(obj).attr('title')=='启用'){

                //发异步把用户状态进行更改
			  jQuery.ajax({  
				url: "{:url('Admin/Deposit/changeState')}",  
				type: "post",  
				dataType: "json",  
				async: true,  
				data: {
				id   : id,
				state: 0
				},  
				success: function(data){  
					if(data.code){					
					    $(obj).attr('title','停用')
						$(obj).find('i').html('&#xe62f;');

						$(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已停用');
						layer.msg('已停用!',{icon: 5,time:1000});
					
					
					}else{
						layer.msg('管理员状态改变失败!!',{icon: 5,time:1000});
					}
					
				},
				error: function (XMLHttpRequest, textStatus, errorThrown) {	
						layer.msg('执行时发生一个未知错误！错误代码：'+textStatus,{icon: 5,time:3000});
				}			
			});				


              }else{
			  
			  
			  
                //发异步把用户状态进行更改
			  jQuery.ajax({  
				url: "{:url('Admin/Deposit/changeState')}",  
				type: "post",  
				dataType: "json",  
				async: true,  
				data: {
				id   : id,
				state: 1
				},  
				success: function(data){  
					if(data.code){	
					
						$(obj).attr('title','启用')
						$(obj).find('i').html('&#xe601;');

						$(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已启用');
						layer.msg('已启用!',{icon: 5,time:1000});					
					
					}else{
						//$(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已启用');
						
						layer.msg('管理员状态改变失败!!',{icon: 5,time:1000});
					}
					
				},
				error: function (XMLHttpRequest, textStatus, errorThrown) {	
						layer.msg('执行时发生一个未知错误！错误代码：'+textStatus,{icon: 5,time:3000});
				}				
			});				  
			  
			  
			  
              }
              
          });
      }

      /*用户-删除*/
      function member_del(obj,id){
          layer.confirm('确认要删除吗？',function(index){
              //发异步删除数据
			  jQuery.ajax({  
				url: "{:url('Admin/Deposit/del')}",  
				type: "post",  
				dataType: "json",  
				async: true,  
				data: {
				id: id
				},  
				success: function(data){  
					if(data.code){
						$(obj).parents("tr").remove();
						layer.msg(data.msg,{icon:1,time:1000});
					}else{
						layer.msg(data.msg,{icon:1,time:1000})
					}
					
				} ,
				error: function (XMLHttpRequest, textStatus, errorThrown) {	
						layer.msg('执行时发生一个未知错误！错误代码：'+textStatus,{icon: 5,time:3000});
				}				
			}); 
              //
          });
      }



      function delAll (argument) {

        var data = tableCheck.getData();
  
        layer.confirm('确认要删除吗？'+data,function(index){

			  jQuery.ajax({  
				url: "{:url('Admin/Deposit/delAll')}",  
				type: "post",  
				dataType: "json",  
				async: true, 			
				data: {
				ids:data
				},  
				success: function(data){  
					if(data.code){
						layer.msg(data.msg, {icon: 1});
						$(".layui-form-checked").not('.header').parents('tr').remove();
					}else{
						layer.msg(data.msg, {icon: 1});
						$(".layui-form-checked").not('.header').parents('tr').remove();
					}
					
				} ,
				error: function (XMLHttpRequest, textStatus, errorThrown) {	
						layer.msg('执行时发生一个未知错误！错误代码：'+textStatus,{icon: 5,time:3000});
				}				
			});		
		
            
        });
      }
    </script>
  </body>

</html>